import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
  state:{//状态:数据
    count:0
  },
  mutations:{
    add(state){
      state.count++
    },
    addN(state,step){
      state.count+=step
    },
    sub(state){
      state.count--
    },
    subN(state,step){
      state.count-=step
    },
  },
  actions:{
    addAsync(context){
      setTimeout(()=>{
        context.commit('add')
      },1000)
    },
    subAsync(context){
      setTimeout(()=>{
        context.commit('sub')
      },1000)
    }
  },
  getters:{
    showNum:state=>{
      return "getters当前最新的数据是:"+state.count
    }
  }
})
